package com.ruoyi.biz.config;

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.DefaultResourceLoader;

import javax.sql.DataSource;

@Configuration
public class BizLiquibaseConfig {

    private static final String LIQUIBASE_CHANGELOG = "classpath:/db/changelog/biz.db.changelog-master.xml";

    @Profile("!test")
    @Bean
    public SpringLiquibase bizLiquibaseForDefault(DataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setChangeLog(LIQUIBASE_CHANGELOG);
        liquibase.setDataSource(dataSource);
        liquibase.setShouldRun(true);
        liquibase.setResourceLoader(new DefaultResourceLoader());
        return liquibase;
    }

    @Profile("test")
    @Bean
    public SpringLiquibase bizLiquibaseForTest(DataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setChangeLog(LIQUIBASE_CHANGELOG);
        liquibase.setDataSource(dataSource);
        liquibase.setContexts("test");
        liquibase.setShouldRun(true);
        liquibase.setResourceLoader(new DefaultResourceLoader());
        return liquibase;
    }

}